package com.kwm;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;



public class Jwt {
    @Test
    public void getTest(){


        Map<String, Object> claims = new HashMap<>();
        claims.put("id",1);
        claims.put("username","Tom");
        String s = "kwm";
        String compact = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,s.getBytes())
                .addClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+12*3600*1000)) //设置过期时间
                .compact();


        System.out.println(compact);
    }

    @Test
    public void ParseJwt(){
        String s = "kwm";

        Claims body = Jwts.parser().setSigningKey(s.getBytes()).parseClaimsJws("eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJUb20iLCJleHAiOjE3NDU0NDQ5MTJ9.0gY1H3bX21uLUx4rA7RGshF90heaWNNTmyXwobNCulc").getBody();

        System.out.println(body);
    }
}
